package game.players.goalkeeper.opp;

import game.players.goalkeeper.Goalkeeper;
import game.players.states.WithBall;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.appearances.Sprite;

public class GoalkeeperWithBallOpp extends WithBall {//extiende de withball para saber hacer un pase a un compañero
	
	private Goalkeeper goalkeeper;
	private boolean goalkicked = false;

	public GoalkeeperWithBallOpp(Goalkeeper goalkeeper) {
		super(goalkeeper);
		this.goalkeeper = goalkeeper;
		this.setTeammates(this.getPlayer().getScene().getOpponents());
		goalkeeper.setAppearance(Sprite.fromImage("/images/arquero_arco.png").crop(31,123,94,72));
	}

	@Override
	public void update(DeltaState deltaState) {
		if(!this.getGoalkeeper().isAccommodated()){
			this.getGoalkeeper().setState(new ReturningToTheArcOppGoalkeeper(this.getGoalkeeper(),true));
		}else{
			if(!this.goalkicked){
				this.getGoalkeeper().setState(new PassingGoalkeeperCPUOpp(this.getGoalkeeper(), this.getLeftClosestMate()));
				this.goalkicked = true;
			}
		}
	}

	@Override
	public boolean isWithBall() {
		return true;
	}

	@Override
	public boolean isRight() {
		return false;
	}

	@Override
	public void loseTheBall() {
		// el arquero no puede perder la pelota		
	}
	
	public Goalkeeper getGoalkeeper(){
		return goalkeeper;
	}

}
